<div>
    <p>
    This step pauses Pipeline execution and wait for previously submitted SonarQube analysis to be completed and returns
    quality gate status. Setting the parameter <code>abortPipeline</code> to true will abort the pipeline if quality gate status is not green.
    </p>
    <p>
    Note: This step doesn't require an executor.
    </p>
    <p>
    Requirements:
      <ul>
        <li>SonarQube server 6.2+</li>
        <li><a href="https://redirect.sonarsource.com/doc/webhooks.html">Configure a webhook</a> in your SonarQube server pointing to <code>&lt;your Jenkins instance&gt;/sonarqube-webhook/</code>. <strong>The trailing slash is mandatory!</strong></li>
        <li>Use <code>withSonarQubeEnv</code> step to run your analysis prior to use this step</li>
      </ul>
    </p>
    <p>
      Example using declarative pipeline:<br/>
      <code><pre>
      pipeline {
        agent none
        stages {
          stage("build & SonarQube analysis") {
            agent any
            steps {
              withSonarQubeEnv('My SonarQube Server') {
                sh 'mvn clean package sonar:sonar'
              }
            }
          }
          stage("Quality Gate") {
            steps {
              timeout(time: 1, unit: 'HOURS') {
                waitForQualityGate abortPipeline: true
              }
            }
          }
        }
      }
      </pre></code>
    </p>
    <p>
      Example using scripted pipeline:<br/>
      <code><pre>
      stage("build & SonarQube analysis") {
          node {
              withSonarQubeEnv('My SonarQube Server') {
                 sh 'mvn clean package sonar:sonar'
              }    
          }
      }
      
      stage("Quality Gate"){
          timeout(time: 1, unit: 'HOURS') {
              def qg = waitForQualityGate()
              if (qg.status != 'OK') {
                  error "Pipeline aborted due to quality gate failure: ${qg.status}"
              }
          }
      }        
      </pre></code>
    </p>
</div>
